local game = require "club.threecard.texas"

local M = game.ui.element()

local function update(self, state)
    local button_no = state.button_no
    local s_blind_no = state.s_blind_no
    local l_blind_no = state.l_blind_no

    if button_no < 1 then
        game.gamelib.log.error("标记错误 no:"..tostring(button_no))
        return
    end

    local button_seat = self.seats[game.seat.to_local(button_no)]
    local s_blind_seat = self.seats[game.seat.to_local(s_blind_no)]
    local l_blind_seat = self.seats[game.seat.to_local(l_blind_no)]

    --todo 动画
    self.button_flag.transform.position = button_seat:get_tag_1().position
    if button_no == s_blind_no then
        self.s_blind_flag.transform.position = s_blind_seat:get_tag_2().position
    else
        self.s_blind_flag.transform.position = s_blind_seat:get_tag_1().position
    end
    self.l_blind_flag.transform.position = l_blind_seat:get_tag_1().position
end

M.store_watchers = {
    ingame = {
        ["$"] = function(self, store, state, args)
            self.root:SetActive(false)
        end,

        ["恢复游戏场景"] = function(self, store, state, args)
            self.root:SetActive(false)
        end,

        ["定庄"] = function(self, store, state, args)
            self:show()
            self.root:SetActive(true)
            update(self, state)
        end
    }
}

function M:ctor(ingame)
    self.res = "club.threecard.texas/ui/ingame.b:button_tag"
    self.seats = ingame.seats
end

return M